Skip to content

Add a title attribute to rendered iframes for accessibility - #236

Open
Htet-Kaung-San wants to merge 2 commits into
python-visualization:mainfrom
Htet-Kaung-San:feature/iframe-title-attr
Open

Add a title attribute to rendered iframes for accessibility#236
Htet-Kaung-San wants to merge 2 commits into
python-visualization:mainfrom
Htet-Kaung-San:feature/iframe-title-attr

Conversation

@Htet-Kaung-San

Copy link
Copy Markdown

Closes #213.

An accessibility audit (axe / WCAG 2.1) of a folium map flags the iframe branca renders in notebooks with "Frames must have an accessible name", because the iframe has no title attribute.

This emits a title attribute when one is available:

  • Figure reuses its existing title, so Figure(title="…") now names both the document <title> and the iframe.
  • IFrame gains a title parameter.
branca.element.Figure(title="Population density")   # -> <iframe ... title="Population density">
branca.element.IFrame("<p>…</p>", title="Detail popup")

Design notes:

  • Non-breaking: when no title is set the rendered output is byte-for-byte identical to before (verified by diffing the render of Figure/IFrame with the attribute code stashed), so existing maps are unaffected. It's opt-in, matching how the issue is framed ("enable adding a title attribute").
  • Escaped: the value goes through html.escape, so a title containing a quote can't break out of the attribute.

Note on stacking: this branch is built on top of #235 (both PRs touch the same iframe templates in element.py). The fullscreen-attribute fix and its two tests belong to #235; the net-new change here is the title attribute and the five *_title_* tests. If you merge #235 first this PR reduces to just that. Happy to rebase or reorder however you prefer.

Testing

Five new tests in tests/test_element.py (title absent by default, set on both Figure and IFrame, and properly escaped). tests/test_element.py is 7 passed, tests/test_colormap.py unaffected. black, flake8 --max-line-length=105 --ignore=E203,W503, and isort --profile black are clean.

Htet-Kaung-San and others added 2 commits August 23, 2026 02:26
Figure._repr_html_ has two iframe templates. The one used when height is
None emits the bare boolean attributes

    allowfullscreen webkitallowfullscreen mozallowfullscreen

but the one used when a height is set wrapped each in quotes:

    "allowfullscreen" "webkitallowfullscreen" "mozallowfullscreen"

so the attribute names came out with literal quote characters around
them and browsers ignored all three -- fullscreen did not work whenever
a height was given. The same branch was also missing the space before
the style attribute, giving height="..."style="...".

Emit the attributes the same way as the height-less branch. Output is
now identical to that branch apart from the width/height.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Accessibility audits flag the iframe that branca renders in notebooks with
"frames must have an accessible name" (WCAG 2.1), because the iframe has no
title attribute (python-visualization#213).

Emit a title attribute when one is available:

- Figure reuses its existing title, so Figure(title="...") now names both
  the document <title> and the iframe.
- IFrame gains a title parameter.

When no title is set the output is byte-for-byte unchanged, so existing
maps are unaffected; the title is HTML-escaped so a value containing a
quote cannot break out of the attribute.

Builds on python-visualization#235 (both touch the same iframe templates); the net new change
here is the title attribute.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Htet-Kaung-San
Htet-Kaung-San force-pushed the feature/iframe-title-attr branch from 42d0672 to 0fe8d36 Compare August 23, 2026 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Accessibility issue - possible to enable adding HTML attributes to rendered iframe elements?

1 participant